package com.mths.server.entity;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;

@Entity
@SQLDelete(sql = "update META_DATA set status='P' where objid=?")
@Where(clause = "status='A'")
@Table(name = "META_DATA")
public class MetaData extends AbstractEntity {

	@Column(name = "FIELD_ID", length = 25, nullable = false)
	private String fieldId;

	@Column(name = "FIELD_TYPE", length = 50, nullable = false)
	private String fieldType;

	@Column(name = "FILED_NAME", length = 100, nullable = false)
	private String fieldName;

	@Column(name = "FIELD_ORDER", length = 2)
	private Integer fieldOrder;

	@Where(clause = "status='A'")
	@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "metaData")
	private List<MetaDataParam> metaDataParamList;

	public MetaData() {
		super();
		fieldOrder = Integer.valueOf(1);
	}

	public String getFieldType() {
		return fieldType;
	}

	public void setFieldType(String fieldType) {
		this.fieldType = fieldType;
	}

	public String getFieldName() {
		return fieldName;
	}

	public void setFieldName(String fieldName) {
		this.fieldName = fieldName;
	}

	public Integer getFieldOrder() {
		return fieldOrder;
	}

	public void setFieldOrder(Integer fieldOrder) {
		this.fieldOrder = fieldOrder;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = super.hashCode();
		result = prime * result + ((fieldId == null) ? 0 : fieldId.hashCode());
		result = prime * result + ((fieldName == null) ? 0 : fieldName.hashCode());
		result = prime * result + ((fieldOrder == null) ? 0 : fieldOrder.hashCode());
		result = prime * result + ((fieldType == null) ? 0 : fieldType.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (!super.equals(obj))
			return false;
		if (getClass() != obj.getClass())
			return false;
		MetaData other = (MetaData) obj;
		if (fieldId == null) {
			if (other.fieldId != null)
				return false;
		} else if (!fieldId.equals(other.fieldId))
			return false;
		if (fieldName == null) {
			if (other.fieldName != null)
				return false;
		} else if (!fieldName.equals(other.fieldName))
			return false;
		if (fieldOrder == null) {
			if (other.fieldOrder != null)
				return false;
		} else if (!fieldOrder.equals(other.fieldOrder))
			return false;
		if (fieldType == null) {
			if (other.fieldType != null)
				return false;
		} else if (!fieldType.equals(other.fieldType))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "MetaData [fieldId=" + fieldId + ", fieldType=" + fieldType + ", fieldName=" + fieldName + ", fieldOrder=" + fieldOrder
				+ "]";
	}

	public List<MetaDataParam> getMetaDataParamList() {
		return metaDataParamList;
	}

	public void setMetaDataParamList(List<MetaDataParam> metaDataParamList) {
		this.metaDataParamList = metaDataParamList;
	}

	public String getFieldId() {
		return fieldId;
	}

	public void setFieldId(String fieldId) {
		this.fieldId = fieldId;
	}

}